package com.ygqh.baby.service.impl;
import java.util.List;
import java.util.Map;

import  com.ygqh.baby.ao.QueryInfo;
import  com.ygqh.baby.ao.ResultSet;
import  com.ygqh.baby.po.YgProductBookDetail;
import  com.ygqh.baby.mapper.YgProductBookDetailMapper;
import  com.ygqh.baby.service.YgProductBookDetailService;

import  org.springframework.util.Assert;

import java.util.Arrays;

import  org.springframework.stereotype.Service;
import  org.springframework.beans.factory.annotation.Autowired;

import  com.ygqh.baby.po.YgProductBookDetailExample;
import  com.ygqh.baby.ao.DataStatus;

@Service
public class YgProductBookDetailServiceImpl implements YgProductBookDetailService{
	
	@Autowired
	private YgProductBookDetailMapper ygProductBookDetailMapper;
	
	@Override
	public List<YgProductBookDetail> find() {
		YgProductBookDetailExample example = new YgProductBookDetailExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return ygProductBookDetailMapper.selectByExample(example);
	}

	@Override
	public int findCount() {
		YgProductBookDetailExample example = new YgProductBookDetailExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return ygProductBookDetailMapper.countByExample(example);
	}

	@Override
	public YgProductBookDetail findById(Long id) {
		return ygProductBookDetailMapper.selectByPrimaryKey(id);
	}


	

	@Override
	public int save(YgProductBookDetail ygProductBookDetail) {
		return ygProductBookDetailMapper.insertSelective(ygProductBookDetail);
	}

	@Override
	public int update(YgProductBookDetail ygProductBookDetail) {
		return ygProductBookDetailMapper.updateByPrimaryKeySelective(ygProductBookDetail);
	}

	@Override
	public ResultSet<YgProductBookDetail> search(QueryInfo queryInfo,String q) {
		List<YgProductBookDetail>  list =  ygProductBookDetailMapper.selectSuper(queryInfo, q);
		int count = ygProductBookDetailMapper.countSuper(q);
		ResultSet<YgProductBookDetail> resultSet = new ResultSet<YgProductBookDetail>(count,list);
		return resultSet;
	}

	@Override
	public int deleteSoft(Long[] ids) {
		Assert.notEmpty(ids);
		YgProductBookDetailExample example = new YgProductBookDetailExample();
		example.createCriteria().andIdIn(Arrays.asList(ids));
		YgProductBookDetail record = new YgProductBookDetail();
		record.setStatus(DataStatus.Delete);

		return ygProductBookDetailMapper.updateByExampleSelective(record, example);
	}
	
	@Override
	public int deleteSoft(Long id) {
		return this.deleteSoft(new Long[]{id});
	}

	@Override
	public int saveOrUpdate(YgProductBookDetail ygProductBookDetail) {
		int r = 0;
		if(ygProductBookDetail.getId() != null) {
			r = this.update(ygProductBookDetail);
		}else {
			r = this.save(ygProductBookDetail);
		}
		return r;
	}
	@Override
	public List<Map<String,Object>>  search(Long bookId) {
		List<Map<String,Object>>  list =  ygProductBookDetailMapper.selectSuperByBookId(bookId);
		return list;
	}

}

